<template>
	<view class="content">
		<view>二维码数据是：{{result}}</view>
		<button class="btn" type="primary" @tap="scanCode()">打开扫码</button>
	</view>

</template>

<script>
	let qrcode = require('@/utils/qrcode.js')
	export default {
		data() {
			return {
				result: '' //获取到的二维码内容

			}
		},

		methods: {
			open() {
				uni.navigateTo({
					url: '../text/text'
				});
			},
			scanCode() {
			let that = this
			// 调用uni提供的调用相机api
			uni.chooseImage({
				sizeType: ['original'],
				count: 1,
				success: res => {
					const tempFilePaths = res.tempFilePaths[0] // 获取到二维码图片的链接
					qrcode.decode(tempFilePaths); // 解析二维码图片
					qrcode.callback = res1 => {
						if (res1 == "error decoding QR Code") {
							uni.showToast({
								title: "识别二维码失败，请重新上传！",
								duration: 2000,
								icon: 'none'
							})
						} else {
							// 解析成功返回二维码链接
							console.log(res1) // 这打印的是扫码扫出来的东西

						}
						this.result = res1
					}
				}
			});
		}
		},

		onShow() {
			let pages = getCurrentPages();
			let currPage = pages[pages.length - 1];
			if (currPage.data) {
				this.result = currPage.data.result
				console.log(this.result, currPage.data.result, '扫码返回')
			}

		},
		


	}
</script>

<style>
	.content {
		width: 100%;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}

	.btn {
		width: 50%;
	}
</style>
